package com.example.steveaoblogdemo.utils;

import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Client;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.UUID;

/**
 * 七牛云工具类
 */
@Component
public class QiNiuUtil {
    public static String getRandomImageName(String fileName){
        //获取后缀
        int index = fileName.lastIndexOf(".");
        String suffix = fileName.substring(index);

        //校验文件
        if (".jpg".equals(suffix)||".jpeg".equals(suffix)||".png".equals(suffix)){
            String uuid = UUID.randomUUID().toString().replace("-","");
            String path = uuid + suffix;
            return path;
        }else {
            throw new IllegalArgumentException();
        }
    }
 
}